class BundleVariationsController < ApplicationController
  # GET /bundle_variations
  # GET /bundle_variations.xml
  def index
    @bundle_variations = BundleVariation.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @bundle_variations }
    end
  end

  # GET /bundle_variations/1
  # GET /bundle_variations/1.xml
  def show
    @bundle_variations = BundleVariation.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @bundle_variations }
    end
  end

  # GET /bundle_variations/new
  # GET /bundle_variations/new.xml
  def new
    basic_data
    
    @bundle_variations = BundleVariation.new
    # @bundle_variations.trial_period = TrialPeriod.new
    # @bundle_variations.trial_periods.build
    # @trial_period = TrialPeriod.new
    # @bundle_variations.build_trial_period 

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @bundle_variations }
    end
  end

  # GET /bundle_variations/1/edit
  def edit
    basic_data
    
    @bundle_variations = BundleVariation.find(params[:id])
    @statuses = BundleVariation.statuses
  end

  # POST /bundle_variations
  # POST /bundle_variations.xml
  def create
    basic_data
    
    @bundle_variations = BundleVariation.new(params[:bundle_variation])

    respond_to do |format|
      if @bundle_variations.save
        flash[:notice] = 'BundleVariations was successfully created.'
        format.html { redirect_to(@bundle_variations) }
        format.xml  { render :xml => @bundle_variations, :status => :created, :location => @bundle_variations }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @bundle_variations.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /bundle_variations/1
  # PUT /bundle_variations/1.xml
  def update
    basic_data
    
    @bundle_variations = BundleVariation.find(params[:id])
    @statuses = BundleVariation.statuses

    respond_to do |format|
      if @bundle_variations.update_attributes(params[:bundle_variation])
        flash[:notice] = 'BundleVariations was successfully updated.'
        format.html { redirect_to(@bundle_variations) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @bundle_variations.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /bundle_variations/1
  # DELETE /bundle_variations/1.xml
  def destroy
    @bundle_variations = BundleVariation.find(params[:id])
    @bundle_variations.destroy

    respond_to do |format|
      format.html { redirect_to(bundle_variations_url) }
      format.xml  { head :ok }
    end
  end
  
  private
  def basic_data
    @bundles = Bundle.find(:all)
    @frequency = BundleVariation.frequency
  end
end
